package bar.dark.lee.common;

import java.util.ArrayList;

import bar.dark.lee.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class KeyValueAdapter extends ArrayAdapter<KeyValueData>
{
	private ArrayList<KeyValueData> list;

	public KeyValueAdapter(Context context, int textViewResourceId,
			ArrayList<KeyValueData> list)
	{
		super(context, textViewResourceId, list);
		this.list = list;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View v = convertView;
		
		if (v == null)
		{
			LayoutInflater li = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			v = li.inflate(R.layout.list_item_key_value, null);
		}
		
		KeyValueData data = list.get(position);
		
		TextView key = (TextView) v.findViewById(R.id.listItemKey);
		TextView value = (TextView) v.findViewById(R.id.listItemValue);
		
		key.setText(data.getKey());
		value.setText(data.getValue());
		
		return v;
	}
}
